package com.ericsson.enap.modules.monitor.job;

import com.ericsson.common.quartz.job.MainJob;
import com.ericsson.common.quartz.service.QuartzTableService;
import com.ericsson.enap.modules.monitor.service.EpcCronHandler;
import com.sun.net.httpserver.HttpServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.net.InetSocketAddress;

/**
 * @description:
 * @author: wangjingshi
 * @create: 2020-12-07 11:32
 */
@Component
public class TestJob3 implements MainJob {

    @Autowired
    QuartzTableService quartzTableService;
    @Autowired
    EpcCronHandler epcCronHandler;
    @Value("${cronPort}")
    private int cronPort;

    @Override
    public void doTask() {
        try {
            HttpServer httpServer = HttpServer.create(new InetSocketAddress(cronPort), 0);
            httpServer.createContext("/epcCron", epcCronHandler);
            httpServer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Job start.....");
        quartzTableService.startJobs();
    }
}
